package com.tanger.im.service.address;

import com.tanger.common.exception.AbstractController;
import com.tanger.common.result.ActionResult;
import com.tanger.common.utils.StringUtil;
import com.tanger.im.entity.ImUserAddress;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * @Description 用户控制层
 * @Author Hchenbin
 * @Date 2023/12/25 9:19
 * @Version 1.0
 */
@RestController
@RequestMapping("/tanger/api/im/user:address")
@Api(value = "IM:IM用户地址",tags="IM:IM用户地址")
public class IMUserAddressController extends AbstractController{

    @Autowired
    private IMUserAddressService service;

    @ApiImplicitParam(name = "id", value = "地址ID", required = true, paramType = "query" ,dataType = "Long")
    @ApiOperation(value = "按地址ID获取地址详情")
    @GetMapping("/findOne")
    public ActionResult<ImUserAddress> findOne(@RequestParam Long id){
        if (StringUtil.isNull(id)) {
            return ActionResult.buildResultError("参数缺失");
        }
        return ActionResult.buildResultSuccess(service.findOne(id));
    }

    @ApiImplicitParam(name = "userId", value = "IM用户ID", required = true, paramType = "query" ,dataType = "Long")
    @ApiOperation(value = "按IM用户ID获取地址详情")
    @GetMapping("/findByUserId")
    public ActionResult<ImUserAddress> findByUserId(@RequestParam Long userId){
        if (StringUtil.isNull(userId)) {
            return ActionResult.buildResultError("参数缺失");
        }
        return ActionResult.buildResultSuccess(service.findOneByUserId(userId));
    }

    @ApiOperation(value = "保存IM用户地址信息")
    @PostMapping("/save")
    public ActionResult save(@RequestBody ImUserAddress vo) {
        if (Objects.isNull(vo)) {
            return ActionResult.buildResultError("参数缺失");
        }
        return service.save(vo);
    }
}

